package org.tis.tools.demo.module.swagger.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.demo.module.swagger.controller.request.NewUser;
import org.tis.tools.demo.module.swagger.entity.User;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author shiunlai
 * @dat 2018-08-12
 */
@Api(tags = "用户(User)服务")
@RestController
@RequestMapping("/user")
public class UserController {

    Logger logger = LoggerFactory.getLogger(UserController.class);

    @ApiOperation("根据GUID获取用户")
    @GetMapping("/byid/{guid}")
    public User getByID(@ApiParam("用户的guid") @PathVariable String guid) {
        return new User(guid);
    }

    @ApiOperation("根据用户代码查询用户")
    @GetMapping("/bycode/{code}")
    public User getByCode(@ApiParam("用户代码") @PathVariable String code) {
        return new User(code);
    }

    @ApiOperation("获取所有用户(支持分页)")
    @GetMapping("/list")
    public List<User> list(@ApiParam("翻页查询对象，其中查询条件为用户对象") @RequestBody @Validated SmartPage<User> page) {
        logger.debug(page.toString());
        return new ArrayList();
    }

    @ApiOperation("新增一个用户")
    @PostMapping
    public void add(@RequestBody @Validated NewUser newUser) {
        logger.debug(newUser.toString());
    }

    @ApiOperation("新增一个用户(指定关键值)")
    @PostMapping("/keys")
    public void addByValue(
            @ApiParam("用户姓名") @RequestParam String name,
            @ApiParam("年龄") @RequestParam Integer age,
            @ApiParam("生日") @RequestParam Date birthday) {
        logger.debug(name + age + birthday);
    }

    @ApiOperation("修改用户")
    @PutMapping
    public void update(@ApiParam("待修改的用户") @RequestBody @Validated User upUser) {
        logger.debug(upUser.toString());
    }

    @ApiOperation("根据guid删除用户")
    @DeleteMapping("/guid/{guid}")
    public void deleteByID(@ApiParam("用户的GUID") @RequestParam("guid") String GUID) {
    }

    @ApiOperation("根据用户编号删除用户")
    @DeleteMapping("/code/{code}")
    public void deleteByCode(@ApiParam("用户编号") @RequestParam("code") String userCode) {
    }
}
